<template>
  <div style="height: 100%; background: #e8e8e8">
    <van-search v-model="sampleCode" show-action placeholder="请输入搜索样衣号" @search="getSample" >
      <template #action>
        <div @click="getSample">搜索</div>
      </template>
    </van-search>
    <div style="padding: 10px;">
    <!-- <van-list
     :loading="loading"
     :finished="finished"
     finished-text="没有更多了"
    > -->
      <!-- <van-cell is-link v-for="item in sealBillList" :key="item.id" :title="item.billNo" @click="toIssuesList(item)"></van-cell> -->
      <div v-for="item in sealBillList" :key="item.id" @click="toIssuesList(item)"
       style="padding: 10px; background-color: #fff; border-radius: 7px; margin-bottom: 10px;">
        <div style="font-size: 16px;color: #323233;">单号：{{ item.billNo }}</div>
        <div style="font-size: 14px;color: #323233;">样衣号：{{ item.sampleCode }}</div>
        <div style="font-size: 14px;color: #323233;">品名：{{ item.sampleCat }}</div>
      </div>
    <!-- </van-list> -->
    </div>
  </div>
</template>

<script>
import { Notify } from 'vant'
import { getFyBill } from '@api/rd/index'

export default {
  components: {},
  data() {
    return {
      sampleCode: '',
      sealBillList: [],
      loading: false,
      finished: false
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    getSample(e) {
      e.preventDefault();
      this.loadData();
    },
    toIssuesList(item){
      this.$router.push({ path: 'sealIssuesList',query: { billNo: item.billNo, sampleCode: this.sampleCode }})
    },
    async loadData(){
      this.loading = true
      const params = {
        current: 1,
        size: 10
      }
      if(this.$route.query.sampleCode){
        this.sampleCode = this.$route.query.sampleCode
      }
      if(this.sampleCode){
        params.sampleCode = this.sampleCode.toUpperCase()
      }
      console.log(params)
      try{
        const res = await getFyBill(params)
        if (res.code == 200) {
          this.sealBillList = res.data.records
        }else{
          if(res.msg){
            Notify({ type: 'warning', message: res.msg })
          }else{
            Notify({ type: 'warning', message: '获取封样单失败！' })
          }
        }
        //this.sealBillList = [{id: 1, sampleCode: 'P07S86-DT'},{id: 2, sampleCode: 'M04736'}]
      } catch(error) {
        Notify({ type: 'warning', message: '获取封样单失败！' })
      } finally {
        this.loading = false
      }
    }
  }
}
</script>